<template>
 <div class="icons">
    <swiper class="home-swiper" :options="swiperOption" ref="mySwiper">
        <swiper-slide v-for="(page,index) in pages" :key="index">
            <div class="icon" v-for="icon in page" :key="icon.id">
                <div class="icon-img">
                    <img class="icon-img-content" :src="icon.imgUrl" />
                </div>
                <p class="iocn-desc">{{icon.desc}}</p>
            </div>
        </swiper-slide>
    </swiper>
</div>
</template>
<script>
export default {
  name: "HomeIcons",
  props:{
    iconsList:Array
  },
  data() {
    return {
      swiperOption: {
      } 
    };
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.swiper;
    },
    pages(){
        const pages = [];
        this.iconsList.forEach((item,index)=>{
            var page = Math.floor(index/8);
            if(!pages[page]){
              pages[page] = [];
            }
            pages[page].push(item);           
        })
        return pages;
    }
  },
  mounted() {
    // current swiper instance
    // 然后你就可以使用当前上下文内的swiper对象去做你想做的事了
    //   this.swiper.slideTo(3, 1000, false)
  }
};
</script>
<style lang="scss" scoped>
@import "~style/public.scss";

  .icon {
    width: 25%;
    overflow: hidden;
    height: 0rem;
    padding-bottom: 25%;
    float: left;
    position: relative;
    .icon-img {
      position: absolute;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0.44rem;
      box-sizing: border-box;
      padding: 0.1rem;
      .icon-img-content {
        display: block;
        margin: 0 auto;
        height: 100%;
      }
    }
    .iocn-desc {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      height: 0.44rem;
      line-height: 0.44rem;
      text-align: center;
      color: $darkTextcolor;
      @include ellipse();
    }
  }

</style>
